--[[
编辑模式 
]]
local CardEliminateAll =  require("app.util.CardEliminateAll")
local CardEditorView =  require("app.views.editor.CardEditorView")

local FightController = require("app.controllers.FightController")
local EditorController = class("EditorController",FightController)




--[[
 获取单例
]]
local instance = nil;
function EditorController.getInstance()
	if instance == nil then
		instance = EditorController.new();
	end
	
	return instance;
end





function EditorController:initView()
	EditorController.super.initView(self);
	
	local  tipLayer = self.scene_.tipLayer_;
	self.CardEditorView_ = CardEditorView.new();
	self.CardEditorView_:initView();
	tipLayer:addChild(self.CardEditorView_);
	self.CardEditorView_:setVisible(false);
	
	local  boundingBox= self.CardEditorView_:getCascadeBoundingBox();
	local size = boundingBox.size --self.CardList_:getContentSize();
	local origin = boundingBox.origin
	self.CardEditorView_:setPosition(20,display.height-size.height);
	
end


--事件响应
function EditorController:touchByCardSprite(event,targetCard)	
	
	
	
    if event.name == "began" then
    	self.CardEditorView_:updateView(targetCard);
	elseif event.name == "moved" then
	elseif event.name == "ended" then
    	
    	local role = self.model_:getObject("static:0_0");
		local roleCardSpriteId = role.cardSpriteId_;
		local roleCardSpriteId = role.cardSpriteId_;
		local targetCardSpriteId = targetCard.cardSpriteId_;
		
		local targetXIndex,targetYIndex = targetCard:getXYIndexById();
		local targetX,targetY = CardUtil.getCardPositionByIndex(targetXIndex,targetYIndex)
		role:moveTo(targetX,targetY);
		
		local roleXIndex,roleYIndex = role:getXYIndexById();
		local roleX,roleY = CardUtil.getCardPositionByIndex(roleXIndex,roleYIndex)
		targetCard:moveTo(roleX,roleY);
    
    end
    return true
end










return EditorController
